package com.oktest.measure.kt

import android.content.Context
import android.graphics.drawable.AnimationDrawable
import android.graphics.drawable.Drawable
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import cc.shinichi.library.ImagePreview
import com.chad.library.adapter.base.BaseQuickAdapter
import com.oktest.measure.R
import kotlinx.android.synthetic.main.recyclerview_empty_layout.view.*

/**
 * @Author hhh
 * @Date 2020/10/27
 */

fun showBigImage(context: Context, imagePath: List<String>, index: Int) {
    if (imagePath.isEmpty()) {
        return
    }
    ImagePreview.getInstance()
        .setContext(context)
        .setImageList(imagePath)
        .setIndex(index)
        .setShowDownButton(false)
        .setShowIndicator(true)
        .setShowCloseButton(true)
        .setEnableDragClose(true)
        .setEnableUpDragClose(true)
        .start()
}


// recyclerView设置空View
fun RecyclerView.emptyView(msg: String = "没有数据", block: () -> Unit) {
    val emptyView = View.inflate(context, R.layout.recyclerview_empty_layout, null)
    emptyView.tvEmpty.text = msg
    val quickAdapter = this.adapter as BaseQuickAdapter<*, *>
    quickAdapter.setEmptyView(emptyView)
    emptyView.setOnClickListener {
        block()
    }
}

fun Drawable?.start() {
    if (this is AnimationDrawable) {
        this.start()
    }
}